package com.example.fragments;

import java.util.TooManyListenersException;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Point;
import android.view.Display;
import android.view.Menu;
import android.view.WindowManager;

public class MainActivity extends Activity {

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		/*
		FragmentManager frag = getFragmentManager();
		FragmentTransaction fragTran = frag.beginTransaction();
		
		//Pega informação da atual tela
		WindowManager winMan = getWindowManager();
		Display d = winMan.getDefaultDisplay();
		
		int measureWidth;
		int measureHeight;
		
		//compatibilidade de versoes
		if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2){
			measureWidth = d.getWidth();
			measureHeight = d.getHeight();
		}else{
			Point point = new Point();
			d.getSize(point);
			measureHeight = point.y;
			measureWidth = point.x;
		}
		
		if(measureWidth > measureHeight){
			//landscape mode
			
			Fragment1 frag1 = new Fragment1();
			//android.R.id.content refere-se a tela de conteudo da activity
			fragTran.replace(android.R.id.content, frag1);
		}else{
			
			Fragment2 frag2 = new Fragment2();
			fragTran.replace(android.R.id.content, frag2);
		}
		
		//AddToBackStack faz com que o fragment va para o back stack. Ou seja,
		//ao aperta o botao de voltar, ele vai para pilha de baixo e permite
		//a aplicação anterior ficar ativa
		//Esse comportamento eé padrao em activities, mas em fragment é preciso seta-la
		//como abaixo
		fragTran.addToBackStack(null);
		fragTran.commit();
		
		*/
		
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
